#!/usr/bin/env bash
# ref url: https://docs.aws.amazon.com/emr/latest/ManagementGuide/emr-plan-bootstrap.html
c_date=$(date "+%Y%m%d-%H%M%S")
sudo mkdir -p /mnt/var/lib/instance-controller/public/shutdown-actions/
sudo touch /mnt/var/lib/instance-controller/public/shutdown-actions/shutdown_broadcast.sh
sudo chmod 666 /mnt/var/lib/instance-controller/public/shutdown-actions/shutdown_broadcast.sh
cat << EOF > /mnt/var/lib/instance-controller/public/shutdown-actions/shutdown_broadcast.sh
if [ -d /etc/spark/conf ]
then
  sudo touch /mnt/var/lib/instance-controller/public/shutdown-actions/${c_date}.hello
  aws s3 cp /mnt/var/lib/instance-controller/public/shutdown-actions/${c_date}.hello s3://testjimmy/${c_date}.hello
fi
EOF
